package com.timebank.volunteer.pojo.entity;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * 地址簿
 * @author shiliuyinzhen
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder
@ApiModel("地址簿")
public class AddressBook {

    @ApiModelProperty("志愿服务Id")
    private Long volunteerId;

    /** 国家 */
    @ApiModelProperty(value = "国家")
    private String country;

    @ApiModelProperty(value = "省份")
    private String province;

    @ApiModelProperty(value = "城市")
    private String city;

    @ApiModelProperty(value = "城市编码")
    private String citycode;

    @ApiModelProperty(value = "区/县级名称")
    private String district;

    @ApiModelProperty(value = "区/县级编码")
    private String adcode;

    @ApiModelProperty(value ="乡镇")
    private String township;

    @ApiModelProperty(value = "街道")
    private String street;

    @ApiModelProperty(value = "门牌")
    private String number;

    @ApiModelProperty(value = "经纬度信息")
    private String location;

    @ApiModelProperty(value = "具体地址")
    private String address;

    @ApiModelProperty("删除标志")
    private Integer delFlag;

    /**
     * 根据志愿服务id和地理信息
     * @param volunteerId
     * @param geocodeResponse
     * @return
     */
    public static AddressBook createAddressBook (Long volunteerId,GeocodeResponse geocodeResponse){
        Geocodes geocodes = geocodeResponse.getGeocodes();
        return AddressBook.builder()
                .volunteerId(volunteerId)
                .country(geocodes.getCountry())
                .province(geocodes.getProvince())
                .city(geocodes.getCountry())
                .citycode(geocodes.getCitycode())
                .district(geocodes.getDistrict())
                .adcode(geocodes.getAdcode())
                .township(geocodes.getTownship())
                .street(geocodes.getStreet())
                .number(geocodes.getNumber())
                .location(geocodes.getLocation())
                .address(geocodes.getFormatted_address())
                .build();
    }
}
